;; host/table.scm - (c) rohan drape, 2000-2005

;; Must provide the basic hashing procedures 'eq-hash-code' and
;; 'equal-hash-code'.  The first hashes to the same value for entities
;; that are eq? the second to the same value for entities that are
;; equal?.

;; Must provide a hash table implementation that has the procedures:
;; make-hash-table, hash-table?, hash-table-put!, hash-table-get,
;; hash-table-remove!, hash-table-map, hash-table-for-each.

(module
 table mzscheme

;; Aliases

(define (make-table) (make-hash-table 'equal))
(define (make-tableW) (make-table 'weak))
(define table? hash-table?)
(define table-get hash-table-get)
(define table-put! hash-table-put!)
(define table-remove! hash-table-remove!)
(define table-traverse hash-table-for-each)
(define (table-for-each p t) (hash-table-for-each t p))
(define (table-map p t) (hash-table-map t p))

;; Evaluates to the value in `table' associated with `key', or to '#f'
;; if there is no value.  

(define (table-get* table key)
  (with-handlers (((lambda (exn) #t)
		   (lambda (exn) #f)))
		 (table-get table key)))

;; make-table: Make a new, empty, table that will use a procedure
;; described by `hash' to test for key equality.

;; table-put!: Make an entry in `table' for the association of `key'
;; with `value'.  If `key' exists the value is over-written, otherwise
;; a new entry is created in the table.

;; table-remove!: Delete all associations from `table' with the given
;; `key'.  The comparison is eq? because hash keys are known to meet
;; that requirement.

;; table-for-each: Apply `procedure' to each key and value stored at
;; `table'.

;; table-map: Construct a list by applying the two argument
;; `procedure' to each key and value stored at `table'.  This
;; behaviour is inherited from mzscheme and is inconsistent with other
;; map procedures, that generate a value of the same type as in the
;; input value.

(provide (all-defined)))
